#!/usr/bin/perl

use IO::Socket;
use strict;
use warnings;
 
my $server = "irc.freenode.net";
my $port = 6667;
my $nick = "SpriggNet";
my $user = "SpriggNet";
my $host = "Toshi-san";
my $name = "SpriggNet";
my $home = "#SquiggTest";
my $socket = new IO::Socket::INET (PeerAddr => $server,
                                   PeerPort => $port,
                                   Proto => "tcp")
                                   or die "Well, that didn't work.";
 
print $socket "NICK $nick\r\n";
print $socket "USER $user $host $server :$name\r\n";

while (my $in = <$socket>) {
   print $in;
    last if ($in =~ m/PRIVMSG SpriggNet :/);
 }

print "arrived\n";
print $socket "JOIN $home\r\n"; 


while (my $in = <$socket>) {
  if ($in =~ m/^PING (:[^ ]+)$/i) {
      print $socket "PONG :$1\r\n";
    }
   print $in;
   print $socket "ACTION :is listening"; 
   print $socket "PRIVMSG $home :I hear ya";
  if ($in =~ m/die, SpriggNet/i) {
      print "Dying, sir.\n";
      print $socket "QUIT leavin'";
      last;
    }
}
